package com.whq.mvc.mq;

import com.whq.mvc.config.AmqpConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class MqProduct {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    //同步库存扣减消息
    public void sendDeductMessage(Integer itemId,Integer amount){
        Map<String, Object> map = new HashMap<>();
        map.put("itemId",itemId);
        map.put("amount",amount);
        rabbitTemplate.convertAndSend(AmqpConfig.MS_EXCHANGE,AmqpConfig.DEDUCT_ROUTEINGKEY,map);
    }
}
